package com.btpn.custody.dao.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.btpn.custody.dao.ITL_MD;
import com.btpn.custody.entity.TL_MD;

@Repository("TL_MD_DaoHibernate")
public class TL_MD_DAO implements ITL_MD {

	protected HibernateTemplate template = null;
	
	@Autowired @Required
	public void setSessionFactory(SessionFactory sessionFactory) {
		template = new HibernateTemplate(sessionFactory);
	}
	
	@Override
	public TL_MD get(Long id) {
		return template.get(TL_MD.class, id);
	}

	@Override
	public List<TL_MD> findAll() {
		return template.loadAll(TL_MD.class);
	}

	@Override
	public Integer getCount() {
		return Integer.valueOf(findAll().size());
	}

	@Override
	public Serializable create(TL_MD traceMD) {
		return template.save(traceMD);		
	}

	@Override
	public void delete(Long id) {
		template.delete(get(id));
	}
}